var addPosBtnSubmit=false;
var addUserBtnSubmit=false;
$(function () {

	//新增职务
	$('#addPosBtn').on('click', function(e) {
		//通知浏览器不要执行与事件关联的默认动作	
		e.preventDefault();
		var treeObj = $.fn.zTree.getZTreeObj("orgTree");
		var nodes = treeObj.getSelectedNodes();
		/*if(nodes.length<=0){
			JY.Model.info("您没有选择任部门!");
			return;
		}*/
		cleanPosForm();
		JY.Model.edit("auPosDiv","新增部门",function(){
			 if(JY.Validate.form("auPosForm")){
				 var that =$(this);
				 if(addPosBtnSubmit){
					 layer.msg("不能重复提交");
					 return;
				 }
				 addPosBtnSubmit=true;
				 JY.Ajax.doRequest("auPosForm",jypath +'/backstage/org/position/addPos',null,function(data){	
					 addPosBtnSubmit=false;
					that.dialog("close"); 
		        	//JY.Model.info(data.resMsg,function(){refreshOrgTree();getOrgList(1);});
                     layer.msg(data.resMsg,{time:1000,icon: 6});
                     refreshOrgTree();getOrgList(1);
				 }); 
			 }	
		});
	});
	$("#editOrgBtn").on('click',function(e){
		e.preventDefault();
		updateDepartment();
	});
	
	$("#checkOrgBtn").on('click',function(e){
		e.preventDefault();
		checkDepartment();
	});
	
	$("#delOrgBtn").on('click',function(e){
		e.preventDefault();
		delDepartment();
	});
	
	$("#sys_user_add").on('click',function(e){
		e.preventDefault();
		add();
	});
	
	loadOrgTree();
	loadPreOrgTree();
	loadAllRole();
	$("#title1").html("全部&nbsp;<i class='icon-double-angle-right'></i>&nbsp;");
	$("#title2").html("员工");	
	$("#rightOrgDiv").removeClass("hide");
	getOrgList(1);
});

function refreshOrgTree(){
	 JY.Model.loading();
	 loadPreOrgTree();
	 JY.Ajax.doRequest(null,jypath +'/backstage/org/position/getOrgAndPositionTree',{resourcesCode: resourcesCode, resourcesName: "resName_org_tree"},function(data){
			//设置
			$.fn.zTree.init($("#orgTree"),{view:{selectedMulti:false,fontCss:{color:"#393939"}},data:{simpleData: {enable: true}},callback:{onClick:clickOrg}},data.obj);
			JY.Model.loadingClose();	 
	 });	 
}
function loadOrgTree(){
	JY.Ajax.doRequest(null,jypath +'/backstage/org/position/getOrgAndPositionTree',{resourcesCode: resourcesCode, resourcesName: "resName_org_tree"},function(data){
		//设置
		$.fn.zTree.init($("#orgTree"),{view:{selectedMulti:false,fontCss:{color:"#393939"}},data:{simpleData: {enable: true}},callback:{onClick:clickOrg}},data.obj);
		var treeObj = $.fn.zTree.getZTreeObj("orgTree");
/*		var nodes = treeObj.getNodes();
		if(nodes.length>0){
			//默认选中第一个
			treeObj.selectNode(nodes[0]);
			clickOrg(null,null,nodes[0]);
		}*/
		
	});
}
function clickOrg(event,treeId,treeNode) {
	    cleanRightDiv();
		var zTree = $.fn.zTree.getZTreeObj("orgTree"),
		nodes = zTree.getSelectedNodes(),v ="",n ="",o="",p="";	
		for (var i=0, l=nodes.length; i<l; i++) {
			v += nodes[i].name + ",";//获取name值
			n += nodes[i].id + ",";//获取id值
			o += nodes[i].other + ",";//获取自定义值
			var pathNodes=nodes[i].getPath();
			for(var y=0;y<pathNodes.length;y++){
				var name=pathNodes[y].name.replace("组织:","").replace("职务:","");
				p+=name+",";//获取path/name值
			}
		}
		if (v.length > 0 ) v = v.substring(0, v.length-1);	
		if (n.length > 0 ) n = n.substring(0, n.length-1);
		if (o.length > 0 ) o = o.substring(0, o.length-1);
		if (p.length > 0 ) p = p.substring(0, p.length-1);
		var ps=p.split(","),psl=ps.length,title1="",title2="";	
		for(var i=0;i<psl;i++){
			title1+=ps[i]+"&nbsp;<i class='icon-double-angle-right'></i>&nbsp;";
		}	
		title2="员工";
		$("#rightOrgDiv").removeClass("hide");
		$("#title1").html(title1);
		$("#title2").html(title2);	
		$("#baseOrgForm input[name$='userDepartmentId']").prop("value",n);
		$("#userForm input[name$='userDepartmentId']").prop("value",n);
		getOrgList(1);
}
function cleanRightDiv(){
	$("#title1").html("");
	$("#title2").html("");
	$("#title3").html("");
	$("#title4").html("");
	$("#basePosForm input[name$='posId']").prop("value","");
	$("#baseOrgForm input[name$='orgId']").prop("value","");
	$("#rightPosDiv").addClass("hide");
	$("#rightOrgDiv").addClass("hide");
	$("#baseOrgTable tbody").empty();
	$("#basePosTable tbody").empty();
	$("#orgpageing ul").empty();//清空org分页
	$("#pospageing ul").empty();//清空pos分页
}
function loadPreOrgTree(){
	JY.Ajax.doRequest(null,jypath +'/backstage/org/position/getPreOrgTree',{resourcesCode: resourcesCode, resourcesName: "resName_org_tree"},function(data){
		//设置
		$.fn.zTree.init($("#preOrgTree"),{view:{dblClickExpand:false,selectedMulti:false,nameIsHTML:true},data:{simpleData:{enable: true}},callback:{onClick:clickPreOrg}},data.obj);
	});
}
function clickPreOrg(e, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("preOrgTree"),
	nodes = zTree.getSelectedNodes(),v ="",n ="",p="";	
	for (var i=0, l=nodes.length; i<l; i++) {
		v += nodes[i].name + ",";//获取name值
		n += nodes[i].id + ",";	//获取id值
		var pathNodes=nodes[i].getPath();
		for(var y=0;y<pathNodes.length;y++){
			p+=pathNodes[y].name+"/";//获取path/name值
		}
	}
	if (v.length > 0 ) v = v.substring(0, v.length-1);
	if (n.length > 0 ) n = n.substring(0, n.length-1);
	if (p.length > 0 ) p = p.substring(0, p.length-1);
	$("#preOrg").prop("value",p);
	$("#auPosForm input[name$='orgId']").prop("value",n);
	//因为单选选择后直接关闭，如果多选请另外写关闭方法
	hidePreOrg();
}
function emptyPreOrg(){
	$("#preOrg").prop("value","");
	$("#auPosForm input[name$='orgId']").prop("value","0");
}
var preisShow=false;//窗口是否显示
function showPreOrg() {
	if(preisShow){
		hidePreOrg();
	}else{
		var obj = $("#preOrg");
		var offpos = $("#preOrg").position();
		$("#preOrgContent").css({left:offpos.left+"px",top:offpos.top+obj.heith+"px"}).slideDown("fast");	
		preisShow=true;
		$("body").bind("mousedown", onBodyDown); 
	}
}
function hidePreOrg(){
	$("#preOrgContent").fadeOut("fast");
	preisShow=false;
}
function getOrgList(init){
	if(init==1)$("#baseOrgForm .pageNum").val(1);	
	JY.Model.loading();
	JY.Ajax.doRequest("baseOrgForm",jypath +'/system/user/list',{resourcesCode: resourcesCode, resourcesName: "resName_org_tree"},function(data){
		var permitBtn=new Array();
		var objList = $("#btnListJson").html();
		objList=JSON.parse(objList);
		for(ob in objList){
			if(objList[ob].permission=="system:user:view"){
				permitBtn.push({name:"查看",btnFun:"view",icon:"icon-zoom-in color-purple"});
			}else if(objList[ob].permission=="system:user:edit"){
				permitBtn.push({name:"修改",btnFun:"edit",icon:"icon-edit color-blue"});
			}else if(objList[ob].permission=="system:user:delete"){
				permitBtn.push({name:"删除",btnFun:"del",icon:"icon-remove-sign color-red"});
			}else if(objList[ob].permission=="system:user:updPassWord"){
				permitBtn.push({name:"密码初始化",btnFun:"updPassWord",icon:"icon-keyboard color-bright-red"});
			}else if(objList[ob].permission=="estate:project:anthorizedList"){
				//permitBtn.push({name:"授权",btnFun:"authorized",icon:"icon-key color-dark-green"});
			}
		}
		//待修改
		
		     $("#baseOrgTable tbody").empty();
    		 //分页对象
        	 var page=data.obj;
        	 //数据集合
        	 var results=page.rows;
        	 //分页数据
         	 var pageNum=page.pageNumber,pageSize=page.pageSize,totalRecord=page.total;
        	 var html="";
    		 if(results!=null&&results.length>0){			
        		 var leng=(pageNum-1)*pageSize;//计算序号
        		 for(var i = 0;i<results.length;i++){
            		 var l=results[i];
            		 html+="<tr>";
            		 //html+="<td class='center'><label> <input type='checkbox' name='ids' value='"+l.id+"' class='ace' /> <span class='lbl'></span></label></td>";
            		 html+="<td class='center hidden-480'>"+(i+leng+1)+"</td>";
            		 html+=JY.Tags.setFunction(l.id,permitBtn);
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.userName)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.userPhone)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.deptName)+"</td>";
            		 if(l.userStatus=="0") html+="<td class='center hidden-480'><span class='label label-sm label-success'>在用</span></td>";
            		 else             html+="<td class='center hidden-480'><span class='label label-sm arrowed-in'>禁用</span></td>";
            		 
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.roleName)+"</td>";
            		 
            		 html+="</tr>";		 
            	 } 
        		 $("#baseOrgTable tbody").append(html);
        		 JY.Page.setPage("baseOrgForm","orgpageing",pageSize,pageNum,totalRecord,"getOrgList");
        		 
        	 }else{
        		html+="<tr><td colspan='8' class='center'>没有相关数据</td></tr>";
        		$("#baseOrgTable tbody").append(html);
        		$("#orgpageing ul").empty();//清空分页
        	 }	 	        	 
    	 JY.Model.loadingClose();	
	});
}
function cleanPosForm(){
	JY.Tags.cleanForm("auPosForm");
	$("#auPosForm input[name$='orgId']").val('-1');//上级资源
	hidePreOrg();
}
function setPosForm(data){
	var l=data.obj;
	$("#auPosForm input[name$='id']").val(JY.Object.notEmpty(l.id));
	$("#auPosForm input[name$='departmentName']").val(JY.Object.notEmpty(l.departmentName));
	$("#auPosForm input[name$='departmentCode']").val(JY.Object.notEmpty(l.departmentCode));
	$("#auPosForm textarea[name$='remark']").val(JY.Object.notEmpty(l.remark));
	var treeObj = $.fn.zTree.getZTreeObj("preOrgTree");
	var nodes =treeObj.getNodesByParam("id",l.parentId);
	if(JY.Object.notNull(nodes)&&nodes.length>0){
		treeObj.selectNode(nodes[0]);
		clickPreOrg(null,null,nodes[0]);
	}
}
//查看部门
function checkDepartment(){
	cleanPosForm();
	var treeObj = $.fn.zTree.getZTreeObj("orgTree");
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length>0){
		var id=nodes[0].id;
		JY.Ajax.doRequest(null,jypath+'/backstage/org/position/findDepartmentById',{id:id},function(data){
	    	setPosForm(data);    
	    	JY.Model.check("auPosDiv","查看部门");   
		});
	}else{
		//JY.Model.info("您没有选择任部门!");
        layer.msg("您没有选择任部门!",{time:1000,icon: 5});
	}
	
}
//修改部门
function updateDepartment(){
	var treeObj = $.fn.zTree.getZTreeObj("orgTree");
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length>0){
		cleanPosForm();
		var id=nodes[0].id;
		JY.Ajax.doRequest(null,jypath+'/backstage/org/position/findDepartmentById',{id:id},function(data){
	    	setPosForm(data);    
    		JY.Model.edit("auPosDiv","修改部门",function(){
   			     if(JY.Validate.form("auPosForm")){
					 var that =$(this);
					 JY.Ajax.doRequest("auPosForm",jypath+'/backstage/org/position/updateDepartment',null,function(data){
			        	that.dialog("close");
			        	//JY.Model.info(data.resMsg,function(){refreshOrgTree();getOrgList();});
						 layer.msg(data.resMsg,{time:1000,icon: 0});

						 refreshOrgTree();getOrgList();
					 });
				 }
   		    });   
		});
	}else{
		// JY.Model.info("您没有选择任部门!");
        layer.msg("您没有选择任部门!",{time:1000,icon: 5});
	}
	
}
function delDepartment(){
	var treeObj = $.fn.zTree.getZTreeObj("orgTree");
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length>0){
		JY.Model.confirm("请再次确认是否删除该部门吗？",function(){	
			var id=nodes[0].id;
			JY.Ajax.doRequest(null,jypath+'/backstage/org/position/delDepartment',{id:id},function(data){
				//JY.Model.info(data.resMsg,function(){refreshOrgTree();getOrgList();});
                layer.msg(data.resMsg,{time:1000,icon: 0});
                refreshOrgTree();
                getOrgList();
			});
		});
	}else{
		//JY.Model.info("您没有选择任部门!");
        layer.msg("您没有选择任部门!",{time:1000,icon: 5});
	}
		
}

function checkPos(id){
	cleanPosForm();
	JY.Ajax.doRequest(null,jypath+'/backstage/org/position/findDepartmentById',{id:id},function(data){
    	setPosForm(data);    
    	JY.Model.check("auPosDiv","查看部门");   
	});
}




function add(){
	var treeObj = $.fn.zTree.getZTreeObj("orgTree");
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length<=0){
		//JY.Model.info("您没有选择任部门!");
        layer.msg("您没有选择任部门!",{time:1000,icon: 5});
		return;
	}
	$("#userPasswordDiv").show();
	$("#userPasswordComfirmDiv").show();
	clearForm();
	save("新增员工","/system/user/add",true);

}


function edit(id){
	$("#userPasswordDiv").hide();
	$("#userPasswordComfirmDiv").hide();
	clearForm();
	JY.Ajax.doRequest(null,jypath+'/system/user/view',{id:id},function(data){
		setForm(data);    
    	save("修改员工","/system/user/edit",false);  
	});
}

function view(id){
	$("#userPasswordDiv").hide();
	$("#userPasswordComfirmDiv").hide();
	clearForm();
	JY.Ajax.doRequest(null,jypath+'/system/user/view',{id:id},function(data){
    	//setForm(data);
		showForm(data);
    	JY.Model.check("userFormDiv","查看员工");   
	});
}

function del(id){
	JY.Model.confirm("请再次确认是否删除该员工吗？",function(){	
		JY.Ajax.doRequest(null,jypath+'/system/user/delete',{id:id},function(data){
			//JY.Model.info(data.resMsg,function(){getOrgList(1);});
            layer.msg(data.resMsg,{time:1000,icon: 6});
            getOrgList(1);
		});
	});
}

function updPassWord(id){
	JY.Model.confirm("是否初始化密码？",function(){	
		JY.Ajax.doRequest(null,jypath+'/system/user/updPassWord',{id:id},function(data){
			//JY.Model.info(data.resMsg,function(){getOrgList(1);});
            layer.msg(data.resMsg,{time:1000,icon: 0});
		});
	});
}

function save(title,url,isAdd){
	
	JY.Model.edit("userFormDiv",title,function(){
		 var userDepartmentId=$("#userForm input[name$='userDepartmentId']").val();
		 if(userDepartmentId=="-1"){
			 //JY.Model.error("请选择部门");
             layer.msg("请选择部门",{time:1000,icon: 2});
			 return;
		 }
		 var userPhone=$("#userForm input[name$='userPhone']").val();
//		 var regTel = /^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/;
//		 if(!regTel.test(userPhone)){
//			 //JY.Model.error("手机号码格式错误");
//             layer.msg("手机号码格式错误",{time:1000,icon: 2});
//			 return;
//		 }
		 $.ajax({
			url: jypath+'/common/mobile/verifyingMobile',
			params: {
				mobile: userPhone,
			},
			method: 'POST',
			async: false,
			success: function(response){
				var text = Ext.decode(response.responseText);
				if(text.result=="1"){
					if(text.flag != "1"){
						layer.msg("手机号码格式错误",{time:1000,icon: 2});
						return;
					}
				}
			}
		 });
		 if(JY.Validate.form("userForm")){
			 if(isAdd){
				 var userPasswordComfirm=$("#userForm input[name$='userPasswordComfirm']").val();
				 var userPassword=$("#userForm input[name$='userPassword']").val();
				 if(!userPassword){
					 $("#userForm input[name$='userPassword']").tips({side:1,msg:"请输入密码",bg :'#FF2D2D',time:1});
					 return; 
				 }
				 if(userPassword.length<6){
					$("#userForm input[name$='userPassword']").tips({side:1,msg:"密码长度不能小于8位",bg :'#FF2D2D',time:1});
					 return; 
				 }
				 if(!userPasswordComfirm){
					 $("#userForm input[name$='userPasswordComfirm']").tips({side:1,msg:"请输入确认密码",bg :'#FF2D2D',time:1});
					 return; 
				 }
				 if($("#userForm input[name$='userPasswordComfirm']").val().length<6){
					 $("#userForm input[name$='userPasswordComfirm']").tips({side:1,msg:"密码长度不能小于8位",bg :'#FF2D2D',time:1});
					 return; 
				 }
				 if($("#userForm input[name$='userPasswordComfirm']").val().length>20){
					 $("#userForm input[name$='userPasswordComfirm']").tips({side:1,msg:"密码长度不能大于20位",bg :'#FF2D2D',time:1});
					 return; 
				 }
				 
				 /*if(!userPasswordComfirm){
					 $("#userForm input[name$='userPasswordComfirm']").tips({side:1,msg:"请输入确认密码",bg :'#FF2D2D',time:1});
					 return; 
				 }*/
				 if(userPasswordComfirm!=userPassword){
					 $("#userForm input[name$='userPasswordComfirm']").tips({side:1,msg:"两次密码输入不一致, 请重新输入",bg :'#FF2D2D',time:1});
					 return;
				 }
			 }
			 var that =$(this);
			 if(addUserBtnSubmit){
				 layer.msg("不能重复提交");
				 return;
			 }
			 addUserBtnSubmit=true;
//			 JY.Ajax.doRequest("userForm",jypath +url,null,function(data){	
//				that.dialog("close"); 
//	        	//JY.Model.info(data.resMsg,function(){getOrgList(1);});
//                 layer.msg(data.resMsg,{time:1000,icon: 0});
//                 getOrgList(1);
//			 }); 
			 $.ajax({
				type:'POST',
				url:jypath +url,
				data:JY.Object.serialize($("#userForm")),
				dataType:'json',
				success:function(data) { 
					addUserBtnSubmit = false; //执行结束后将状态修改为允许提交
					if(data.res==1){
						layer.msg(data.resMsg,{time:1000,icon: 0});
						that.dialog("close");
						getOrgList(1);
					}else{
						if(JY.Object.notNull(data.resMsg)){
							JY.Model.error(data.resMsg);
						}
					}
				}
			});
		 }	
	});
}
function setForm(data){
	var l=data.obj;
	$("#userForm input[name$='userDepartmentId']").val(JY.Object.notEmpty(l.userDepartmentId));
	$("#userForm input[name$='id']").val(JY.Object.notEmpty(l.id));
	$("#userForm input[name$='userName']").val(JY.Object.notEmpty(l.userName));
	$("#userForm input[name$='userAccount']").val(JY.Object.notEmpty(l.userAccount));
	$("#userForm input[name$='userPhone']").val(JY.Object.notEmpty(l.userPhone));
	$("#userForm input[name$='birthdayStr']").val(JY.Object.notEmpty(l.birthdayStr));
	$("#userForm input[name$='entryTimeStr']").val(JY.Object.notEmpty(l.entryTimeStr));
	$("#userForm select[name$='roleId']").prop("value",JY.Object.notEmpty(l.roleId));
	$("#userForm select[name$='userStatus']").prop("value",JY.Object.notEmpty(l.userStatus));

}

function showForm(data){
	var l=data.obj;
	$("#userForm input[name$='userDepartmentId']").val(JY.Object.notEmpty(l.userDepartmentId));
	$("#userForm input[name$='id']").val(JY.Object.notEmpty(l.id));
	$("#userForm input[name$='userName']").val(JY.Object.notEmpty(l.userName));
	$("#userForm input[name$='userAccount']").val(JY.Object.notEmpty(l.userAccount));
	$("#userForm input[name$='userPhone']").val(JY.Object.notEmpty(l.userPhone));
	$("#userForm input[name$='birthdayStr']").val(JY.Object.notEmpty(l.birthdayStr));
	$("#userForm input[name$='entryTimeStr']").val(JY.Object.notEmpty(l.entryTimeStr));
	$("#userForm select[name$='roleId']").prop("value",JY.Object.notEmpty(l.roleId));
	$("#userForm select[name$='userStatus']").prop("value",JY.Object.notEmpty(l.userStatus));
	$("#userForm input[name$='id']").attr("disabled","disabled");
	$("#userForm input[name$='userName']").attr("disabled","disabled");
	$("#userForm input[name$='userAccount']").attr("disabled","disabled");
	$("#userForm input[name$='userPhone']").attr("disabled","disabled");
	$("#userForm input[name$='birthdayStr']").attr("disabled","disabled");
	$("#userForm input[name$='entryTimeStr']").attr("disabled","disabled");
	$("#userForm select[name$='roleId']").attr("disabled","disabled");
	$("#userForm select[name$='userStatus']").attr("disabled","disabled");
}

function clearForm(){
	JY.Tags.cleanForm("userForm");
	$("#userForm input[name$='userPassword']").val("");
	$("#userForm input[name$='userPasswordComfirm']").val("");
	$("#userForm input[name$='id']").removeAttr('disabled');
	$("#userForm input[name$='userName']").removeAttr('disabled');
	$("#userForm input[name$='userAccount']").removeAttr('disabled');
	$("#userForm input[name$='userPhone']").removeAttr('disabled');
	$("#userForm input[name$='birthdayStr']").removeAttr('disabled');
	$("#userForm input[name$='entryTimeStr']").removeAttr('disabled');
	$("#userForm select[name$='roleId']").removeAttr('disabled');
	$("#userForm select[name$='userStatus']").removeAttr('disabled');
}

function loadAllRole(){
	JY.Ajax.doRequest(null,jypath+'/system/role/listAll',{},function(data){
		var obj=data.obj;
		var allRole='';
		var searchRole='<option value="-1">所有角色</option>';
		$.each(obj,function(n,v) {
			allRole=allRole+'<option value="'+v.id+'">'+v.roleName+'</option>';
			searchRole=searchRole+'<option value="'+v.id+'">'+v.roleName+'</option>';
		});
		$("#roleId").empty();
		$("#roleId").append(allRole);
		
		$("#searchRoleId").empty();
		$("#searchRoleId").append(searchRole);
		
	});
}


function authorized(userId){
	$("#Project_authorityDiv input[name$='userId']").val(userId);
	JY.Ajax.doRequest(null,jypath +'/estate/project/anthorizedList',{delFlag:0,userId,userId},function(data){
	//获取数据
   	 var zNodes=data.obj;
   	 //设置
	 var setting = {check: {enable: true,chkStyle: "checkbox",chkDisabledInherit: true,chkboxType:{"Y":"ps","N":"s"}},data:{simpleData:{enable: true,rootPId:"menu_0000"}}};
     $.fn.zTree.init($("#Project_authorityTree"),setting,zNodes);	   
     JY.Model.edit("Project_authorityDiv","员工授权",function(){
    	 var zTree = $.fn.zTree.getZTreeObj("Project_authorityTree"),
			nodes = zTree.getCheckedNodes(),aus ="";
			for (var i=0, l=nodes.length; i<l; i++) {
				aus += nodes[i].id + ",";
			}
			if (aus.length > 0 ) aus = aus.substring(0, aus.length-1);
			var that =$(this);
			JY.Ajax.doRequest(null,jypath +'/system/userProject/add',{userId:userId,aus:aus},function(data){
				  that.dialog("close");
				  // JY.Model.info(data.resMsg,function(){});
                layer.msg(data.resMsg,{time:1000,icon: 0});
			});
			
     });
	});
}

function onBodyDown(event) {
	if (!(event.target.id == "preOrg" || event.target.id == "preOrgContent" || $(event.target).parents("#preOrgContent").length>0)) {
		hidePreOrg();
	}
}

function importFile(){
	var file = $("#multipartFile").val();
	$.ajaxFileUpload({
		type: "POST",
		url: jypath + "/backstage/org/position/departmentImport",
		fileElementId:'multipartFile',
		dataType: "json",
		success: function(obj) {
			console.log(obj);
		}
	});
}

function importUserFile(){
	$.ajaxFileUpload({
		type: "POST",
		url: jypath + "/backstage/org/position/userInfoImport",
		fileElementId:'userInfoFile',
		dataType: "json",
		success: function(obj) {
			console.log(obj);
		}
	});
}
